package com.example.glxt1.config;

import com.example.glxt1.config.Interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {

    /**
     * 发现如果继承了WebMvcConfigurationSupport，则在yml中配置的相关内容会失效。 需要重新指定静态资源
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/");
        registry.addResourceHandler("swagger-ui.html", "doc.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }


    /**
     * Token拦截器注册
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new TokenInterceptor())
//                .addPathPatterns("/**")//拦截所有请求判断token是否合法，从而决定是否需要登录
//               .excludePathPatterns("/**/login")
//                .excludePathPatterns("/**/register")
//                .excludePathPatterns("/**/import")
//                .excludePathPatterns("/**/export")
//                .excludePathPatterns("/file/**")
//                .excludePathPatterns(    // 不拦截的路径
//                        // 放行swagger相关的
//                        "/swagger-ui/**",
//                        "/swagger-resources/**",
//                        "/v3/api-docs"
//                );

    }

}

